package cn.rokhdelar.ams.business.biz.project.flowablelis;

import cn.rokhdelar.ams.business.biz.project.service.BizProjectInfoService;
import jakarta.annotation.Resource;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.runtime.Execution;

/**
 * 用户被驳回后放弃监听
 * @author 范书铭
 * @date 2025年07月21日 9:44
 */
public class ProjectInitAuditCompanyFinishLis implements ExecutionListener {

    @Resource
    BizProjectInfoService bizProjectInfoService;

    @Override
    public void notify(DelegateExecution execution) {
        // 流程实例结束时执行的逻辑
        String processInstanceId = execution.getProcessInstanceId();
        String processDefinitionId = execution.getProcessDefinitionId();
        // 从执行对象中获取businessKey
        String projcetCode = execution.getProcessInstanceBusinessKey();

        Integer approvalFlowType = execution.getVariable("approvalFlowType", Integer.class);

        // approvalFlowType 为1,开启标准审核流程时，流程结束时将项目状态更新为3
        if (approvalFlowType == 1) {
            bizProjectInfoService.updateStatus(projcetCode, 3);

        }
        // approvalFlowType 为2时，开启简易审核流程时，流程结束时将项目状态更新为2
        else if (approvalFlowType == 2) {
            bizProjectInfoService.updateStatus(projcetCode, 2);
        }

    }
}
